﻿using System;
using System.Runtime.InteropServices;

namespace shbxdv.Ezviz
{
    /// <summary>
    /// 开放SDK接口约束
    /// 页面：https://open.ys7.com/doc/zh/pc/index.html
    /// </summary>
    public class OpenNetStream
    {
        private const string DllName =
        #if X86
                 @"lib\win32\OpenNetStream.dll";
        #else
                @"lib\win64\OpenNetStream.dll";
        #endif
        /**
         *  \brief Message callback error code definition(MessageInfo)
         */
        public const string OPEN_SDK_STREAM_ACCESSTOKEN_ERROR_OR_EXPIRE = "UE001"; 	///< Accesstoken expire or invalid. update accesstoken.
        public const string OPEN_SDK_STREAM_PU_NO_RESOURCE = "UE101";	    ///< Device connection is too many, upgrade the device version, Hikvision devices can consult customer service to obtain the upgrade process.
        public const string OPEN_SDK_STREAM_TRANSF_DEVICE_OFFLINE = "UE102"; 	///< Device offline. Connect the device to network and try again.
        public const string OPEN_SDK_STREAM_INNER_TIMEOUT = "UE103"; 	///< Request to connect device to timeout, detect device network connection is normal.
        public const string OPEN_SDK_STREAM_INNER_VERIFYCODE_ERROR = "UE104"; 	///< Video verificaiton code error, check the verification code marked on the device.
        public const string OPEN_SDK_STREAM_PLAY_FAIL = "UE105"; 	///< Failed to play the video, please check the message callback specific error code iErrorCode.
        public const string OPEN_SDK_STREAM_TRANSF_TERMINAL_BINDING = "UE106"; 	///< The current account has enabled terminal binding. Only the specified device can log in.
        public const string OPEN_SDK_STREAM_VIDEO_RECORD_NOTEXIST = "UE108";     ///< Video record not found.
        public const string OPEN_SDK_STREAM_VTDU_CONCURRENT_LIMIT = "UE109";     ///< Take the flow of concurrent route restrictions, please upgrade to Enterprise Edition
        public const string OPEN_SDK_STREAM_UNSUPPORTED = "UE110";      ///< The type of resolution that the device does not support is selected according to the device preview capability level.

        #region 云台控制命令
        /**  \enum PTZCommand（云台控制命令）
         *  \brief 
         */
        public enum PTZCommand
        {
            UP,
            DOWN,
            LEFT,
            RIGHT,
            UPLEFT,
            DOWNLEFT,
            UPRIGHT,
            DOWNRIGHT,
            ZOOMIN,
            ZOOMOUT,
            FOCUSNEAR,
            FOCUSFAR,
            IRISSTARTUP,
            IRISSTOPDOWN,
            LIGHT,
            WIPER,
            AUTO
        };
        #endregion

        #region 云台操作命令
        /** \enum PTZCommand（云台操作命令 一般情况下，鼠标按下代表开始，鼠标松开代表停止）
         *  \brief PTZ control command 
         */
        public enum PTZAction
        {
            START,
            STOP
        };

        #endregion

        #region 回放数据类型
        //DataCallBack DataType
        public enum CallBackDateType
        {
            NET_DVR_SYSHEAD = 0,
            NET_DVR_STREAMDATA = 1,
            NET_DVR_RECV_END = 2,
        };

        #endregion

        #region SDK初始化
        //Init API
        /// <summary>
        /// 初始化库
        /// </summary>
        /// <param name="szAppId">AppID</param>
        /// <returns></returns>
        [DllImport(DllName, EntryPoint = "OpenSDK_Init")]
        public static extern int OpenSDK_Init(string szAppId);

        /// <summary>
        /// 初始化库
        /// </summary>
        /// <param name="szAuthAddr">认证域名:开放平台认证中心地址，默认地址为：https://openauth.ys7.com .对于开发者而言，请填写此默认地址即可.</param>
        /// <param name="szPlatform">平台域名:开放平台后台地址，默认地址为：https://open.ys7.com .对于开发者而言，请填写此默认地址即可</param>
        /// <param name="szAppId">	向平台申请的AppKey</param>
        /// <returns></returns>
        [DllImport(DllName, EntryPoint = "OpenSDK_InitLib")] //SDK Init
        public static extern int OpenSDK_InitLib(string szAuthAddr, string szPlatform, string szAppId);

        /// <summary>
        /// 释放库
        /// </summary>
        /// <returns></returns>
        [DllImport(DllName, EntryPoint = "OpenSDK_FiniLib")] //SDK Fini
        public static extern int OpenSDK_FiniLib();

        /// <summary>
        /// 设置预链接信息回调
        /// </summary>
        /// <param name="pHandle"></param>
        public delegate void OpenSDK_SetMessageCallback(OpenSDK_MsgHandler pHandle);

        /// <summary>
        /// 设置AccessToken
        /// </summary>
        /// <param name="szAccessToken">AccessToken</param>
        /// <returns></returns>
        [DllImport(DllName, EntryPoint = "OpenSDK_SetAccessToken")] //Set AccessToken
        public static extern int OpenSDK_SetAccessToken(string szAccessToken);

        #endregion

        #region 中间页
        //Mid API
        /// <summary>
        /// 登陆接口
        /// </summary>
        /// <param name="szAccessToken">认证Token</param>
        /// <param name="iAccessTokenLen">认证Token长度</param>
        /// <returns></returns>
        [DllImport(DllName, EntryPoint = "OpenSDK_Mid_Login")]
        public static extern int OpenSDK_Mid_Login(ref IntPtr szAccessToken, ref int iAccessTokenLen);

        /// <summary>
        /// 注销接口, 同OpenSDK_Mid_Login接口配对使用
        /// </summary>
        /// <returns>0表示成功，非0表示失败</returns>
        [DllImport(DllName, EntryPoint = "OpenSDK_Logout")]
        public static extern int OpenSDK_Logout();

        /// <summary>
        /// 设备添加
        /// </summary>
        /// <param name="szAccessToken">认证Token</param>
        /// <param name="szDeviceId">设备Id</param>
        /// <returns></returns>
        [DllImport(DllName, EntryPoint = "OpenSDK_Mid_Device_Add")]
        public static extern int OpenSDK_Mid_Device_Add(string szAccessToken, string szDeviceId);

        #endregion

        #region 数据接口
        //DATA API
        /// <summary>
        /// 获取摄像头列表
        /// </summary>
        /// <param name="pageStart">分页起始页，从0开始</param>
        /// <param name="pageSize">分页大小, 限制最大1000,默认100, 建议不超过100</param>
        /// <param name="pBuf">摄像头列表的JSON字符串</param>
        /// <param name="iBufLen">获取到的数据大小</param>
        /// <returns></returns>
        [DllImport(DllName, EntryPoint = "OpenSDK_Data_GetDevListEx")]
        public static extern int OpenSDK_Data_GetDevListEx(int pageStart, int pageSize, ref IntPtr pBuf, ref int iBufLen);


        /// <summary>
        /// 获取设备详细信息, 包括预览能力级, PTZ, 对讲能力级等.
        /// </summary>
        /// <param name="szDevSerial">设备序列号</param>
        /// <param name="iChannelNo">设备通道号</param>
        /// <param name="bUpdate">是否重新获取设备详细信息, true:重新从萤石平台拿数据, 否则拿缓存信息. true的时机为用户重新登录或者需要刷新设备信息.</param>
        /// <param name="pBuf">监控点信息，需要调用OpenSDK_FreeData接口释放</param>
        /// <param name="iBufLen">监控点信息的长度</param>
        /// <returns>0表示成功，其他值表示失败</returns>
        [DllImport(DllName, EntryPoint = "OpenSDK_Data_GetDevDetailInfo")]
        public static extern int OpenSDK_Data_GetDevDetailInfo(string szDevSerial, int iChannelNo, bool bUpdate, ref IntPtr pBuf, ref int iBufLen);

        /// <summary>
        /// 获取单个设备信息
        /// </summary>
        /// <param name="szAccessToken">认证Token</param>
        /// <param name="szDeviceSerial">设备序列号</param>
        /// <param name="pBuf">摄像头设备信息的JSON字符串</param>
        /// <param name="iBufLen">获取到的数据大小</param>
        /// <returns>0表示成功，非0表示失败</returns>
        [DllImport(DllName, EntryPoint = "OpenSDK_Data_GetDeviceInfo")]
        public static extern int OpenSDK_Data_GetDeviceInfo(string szAccessToken, string szDeviceSerial, ref IntPtr pBuf, ref int iBufLen);

        /// <summary>
        /// 销毁SDK分配的内存
        /// </summary>
        /// <param name="pBuf">SDK分配的内存</param>
        /// <returns>0表示成功，-1表示失败</returns>
        [DllImport(DllName, EntryPoint = "OpenSDK_Data_Free")]
        public static extern int OpenSDK_Data_Free(IntPtr pBuf);

        #endregion

        #region 分配会话
        //PLAY API
        /// <summary>
        /// 申请一个会话Id
        /// </summary>
        /// <param name="MsgCallBack">设置回调函数， OpenSDK_MessageHandler</param>
        /// <param name="pUserID">用户自定义数据，会在pHandle中原样抛出</param>
        /// <param name="pSID">用于接收分配的会话ID</param>
        /// <param name="SIDLen">pSession的长度</param>
        /// <returns></returns>
        [DllImport(DllName, EntryPoint = "OpenSDK_AllocSessionEx")] //SDK Alloc Sessioon
        public static extern int OpenSDK_AllocSessionEx(OpenSDK_MsgHandler MsgCallBack, IntPtr pUserID, ref IntPtr pSID, ref int SIDLen);

        //delegate of message callback api 
        /// <summary>
        /// 消息处理器
        /// </summary>
        /// <param name="sessionID">会话</param>
        /// <param name="msgType">消息类型</param>
        /// <param name="Error"></param>
        /// <param name="Info"></param>
        /// <param name="pUser"></param>
        /// <returns></returns>
        public delegate void OpenSDK_MsgHandler(IntPtr sessionID, EZMessageType msgType, uint Error, string Info, IntPtr pUser);

       // public delegate void DataCallBack(EZDataType dataType, IntPtr data, int len, IntPtr userData);

        /// <summary>
        /// 销毁SDK操作句柄
        /// </summary>
        /// <param name="SID">会话Id，通过OpenSDK_AllocSession()创建</param>
        /// <returns></returns>
        [DllImport(DllName, EntryPoint = "OpenSDK_FreeSession")]//SDK Free Session
        public static extern int OpenSDK_FreeSession(IntPtr SID);

        #endregion

        #region 预览接口
        /// <summary>
        /// 设置数据回调
        /// </summary>
        /// <param name="szSessionId">会话ID</param>
        /// <param name="pDataCallBack">回调函数</param>
        /// <param name="pUser">用户自定义数据，会通过pDataCallBack原样抛出</param>
        /// <returns>0表示成功，-1表示失败</returns>
        [DllImport(DllName)]//Set Data Callback
        public static extern int OpenSDK_SetDataCallBack(IntPtr szSessionId, OpenSDK_DataCallBack pDataCallBack, IntPtr pUser);

        //delegate of data callback api 
        /// <summary>
        /// 数据回调格式
        /// </summary>
        /// <param name="dateType">数据类型</param>
        /// <param name="dateContent">数据内容</param>
        /// <param name="dataLen">数据长度</param>
        /// <param name="pUser">用户自定义数据</param>
        public delegate void OpenSDK_DataCallBack(CallBackDateType dateType, IntPtr dateContent, int dataLen, string pUser);


        /// <summary>
        /// 针对摄像头进行预览 异步接口，返回值只是表示操作成功，不代表播放成功 如果接口返回-1, 结果根据消息回调函数msgid判断, 若msgid=INS_PLAY_START, 表示成功, 若msgid=INS_PLAY_EXCEPTION, 表示失败
        /// </summary>
        /// <param name="szSessionId">会话ID</param>
        /// <param name="hPlayWnd">播放窗口句柄, 如果窗口句柄为NULL表示纯粹取流，不做播放</param>
        /// <param name="szDevSerial">设备序列号</param>
        /// <param name="iChannelNo">设备通道号（默认为均衡-1）</param>
        /// <param name="szSafeKey">视频加密密钥,如果视频未加密, 可以设置为NULL</param>
        /// <returns></returns>
        [DllImport(DllName, EntryPoint = "OpenSDK_StartRealPlayEx")]
        public static extern int OpenSDK_StartRealPlayEx(IntPtr szSessionId, IntPtr hPlayWnd, string szDevSerial, int iChannelNo=(int)VideoLevel.BALANCED, string szSafeKey=null);

        /// <summary>
        /// 针对摄像头进行预览, 指定主\子码流
        /// </summary>
        /// <param name="szSessionId">会话</param>
        /// <param name="hPlayWnd">播放窗口句柄</param>
        /// <param name="szDevSerial">设备序列号</param>
        /// <param name="iChannelNo">设备通道号</param>
        /// <param name="szSafeKey">视频加密密钥,如果视频未加密, 可以设置为NULL</param>
        /// <param name="iStreamType">主子码流 1-主, 2-子, -1-默认码流类型</param>
        /// <returns></returns>
        [DllImport(DllName, EntryPoint = "OpenSDK_StartPlayWithStreamType")]
        public static extern int OpenSDK_StartPlayWithStreamType(IntPtr szSessionId, IntPtr hPlayWnd, string szDevSerial, int iChannelNo, string szSafeKey, int iStreamType);

        /// <summary>
        /// 停止播放播放 异步接口，返回值只是表示操作成功，不代表停止播放成功 如果接口返回-1, 结果根据消息回调函数msgid判断, 若msgid=INS_PLAY_STOP, 表示成功
        /// </summary>
        /// <param name="szSessionId">会话ID</param>
        /// <returns></returns>
        [DllImport(DllName, EntryPoint = "OpenSDK_StopRealPlayEx")]
        public static extern int OpenSDK_StopRealPlayEx(IntPtr szSessionId);

        /// <summary>
        /// 设置或者切换清晰度, 根据OpenSDK_Data_GetDevDetailInfo接口返回信息videoQualityInfos来判断是否支持对应的清晰度类型
        /// </summary>
        /// <param name="szDevSerial">设备序列号</param>
        /// <param name="iChannelNo">设备通道号</param>
        /// <param name="iVideoLevel">视频质量，输入范围在0-3之间, 0-流畅; 1-均衡; 2-高清; 3-超清</param>
        /// <returns></returns>
        [DllImport(DllName, EntryPoint = "OpenSDK_SetVideoLevel")]
        public static extern int OpenSDK_SetVideoLevel(string szDevSerial, int iChannelNo, int iVideoLevel);

        #endregion

        #region 回放接口
        /// <summary>
        /// 录像搜索，包含云存储和设备SD卡录像, 如果关联NVR优先搜索NVR录像 异步接口，返回值只是表示操作成功，不代表搜索成功 如果接口返回-1, 结果根据消息回调函数msgid判断, 若msgid=INS_RECORD_SEARCH_END, 表示成功, 若msgid= INS_RECORD_SEARCH_FAILED, 表示失败
        /// </summary>
        /// <param name="szSessionId">会话Id</param>
        /// <param name="szDevSerial">设备序列号</param>
        /// <param name="iChannelNo">设备通道号</param>
        /// <param name="szStartTime">开始时间</param>
        /// <param name="szStopTime">停止时间</param>
        /// <returns></returns>
        [DllImport(DllName, EntryPoint = "OpenSDK_StartSearchEx")]
        public static extern int OpenSDK_StartSearchEx(IntPtr szSessionId, string szDevSerial, int iChannelNo, string szStartTime, string szStopTime);

        /// <summary>
        /// 开始回放 异步接口，返回值只是表示操作成功，不代表播放成功 如果接口返回-1, 结果根据消息回调函数msgid判断, 若msgid=INS_PLAY_START, 表示成功, 若msgid=INS_PLAY_EXCEPTION, 表示失败
        /// </summary>
        /// <param name="szSessionId">会话Id</param>
        /// <param name="hPlayWnd">播放窗口句柄, 如果窗口句柄为NULL表示纯粹取流，不做播放</param>
        /// <param name="szDevSerial">设备序列号</param>
        /// <param name="iChannelNo">设备通道号</param>
        /// <param name="szSafeKey">视频加密密钥</param>
        /// <param name="szStartTime">开始时间</param>
        /// <param name="szStopTime">停止时间</param>
        /// <returns></returns>
        [DllImport(DllName, EntryPoint = "OpenSDK_StartPlayBackEx")]
        public static extern int OpenSDK_StartPlayBackEx(IntPtr szSessionId, IntPtr hPlayWnd, string szDevSerial, int iChannelNo, string szSafeKey, string szStartTime, string szStopTime);

        /// <summary>
        /// 停止回放 异步接口，返回值只是表示操作成功，不代表停止播放成功 如果接口返回-1, 结果根据消息回调函数msgid判断, 若msgid=INS_PLAY_STOP, 表示成功
        /// </summary>
        /// <param name="szSessionId">会话Id</param>
        /// <returns></returns>
        [DllImport(DllName, EntryPoint = "OpenSDK_StopPlayBackEx")]
        public static extern int OpenSDK_StopPlayBackEx(IntPtr szSessionId);

        /// <summary>
        /// 恢复回放
        /// </summary>
        /// <param name="szSessionId">会话Id</param>
        /// <returns></returns>
        [DllImport(DllName, EntryPoint = "OpenSDK_PlayBackResume")]
        public static extern int OpenSDK_PlayBackResume(IntPtr szSessionId);

        /// <summary>
        /// 暂停回放
        /// </summary>
        /// <param name="szSessionId">会话Id</param>
        /// <returns></returns>
        [DllImport(DllName, EntryPoint = "OpenSDK_PlayBackPause")]
        public static extern int OpenSDK_PlayBackPause(IntPtr szSessionId);

        #endregion

        #region 设备操作相关接口
        //PTZ Control
        /// <summary>
        /// 云台控制 异步接口，返回值只是表示操作成功，不代表云台控制成功 如果接口返回-1, 结果根据消息回调函数msgid判断, 若msgid=INS_PTZCTRL_SUCCESS, 表示成功, 若msgid=INS_PTZCTRL_FAILED, 表示失败
        /// </summary>
        /// <param name="szSessionId">会话ID</param>
        /// <param name="szDevSerial">设备序列号</param>
        /// <param name="iChannelNo">设备通道号</param>
        /// <param name="enCommand">云台控制命令，参见 PTZCommand</param>
        /// <param name="Action">云台操作命令，参见 PTZAction</param>
        /// <param name="iSpeed">速度0-7之间</param>
        /// <returns></returns>
        [DllImport(DllName, EntryPoint = "OpenSDK_PTZCtrlEx")]
        public static extern int OpenSDK_PTZCtrlEx(IntPtr szSessionId, string szDevSerial, int iChannelNo, PTZCommand enCommand, PTZAction Action, int iSpeed);

        #endregion

        #region 视频信息获取
        /// <summary>
        /// 获取OSD时间
        /// </summary>
        /// <param name="szSessionId"></param>
        /// <param name="time"></param>
        /// <returns>0表示成功，-1表示失败</returns>
        [DllImport(DllName, CharSet = CharSet.Ansi)]
        public static extern int OpenSDK_GetOSDTime(IntPtr szSessionId, [In, Out] ref STREAM_TIME time);

        #endregion

        #region 音频相关接口
        /// <summary>
        /// 打开声音
        /// </summary>
        /// <param name="szSessionId">会话Id</param>
        /// <returns>0表示成功，-1表示失败</returns>
        [DllImport(DllName, EntryPoint = "OpenSDK_OpenSound")]
        public static extern int OpenSDK_OpenSound(IntPtr szSessionId);

        /// <summary>
        /// 关闭声音
        /// </summary>
        /// <param name="szSessionId">会话</param>
        /// <returns>0表示成功，-1表示失败</returns>
        [DllImport(DllName, EntryPoint = "OpenSDK_CloseSound")]
        public static extern int OpenSDK_CloseSound(IntPtr szSessionId);

        /// <summary>
        /// 获取音量
        /// </summary>
        /// <param name="szSessionId">会话</param>
        /// <returns>0表示成功，-1表示失败</returns>
        [DllImport(DllName, EntryPoint = "OpenSDK_GetVolume")]
        public static extern ushort OpenSDK_GetVolume(IntPtr szSessionId);

        /// <summary>
        /// 设置音量
        /// </summary>
        /// <param name="szSessionId">会话</param>
        /// <param name="volume">音量大小，0-100之间</param>
        /// <returns>0表示成功，-1表示失败</returns>
        [DllImport(DllName, EntryPoint = "OpenSDK_SetVolume")]
        public static extern int OpenSDK_SetVolume(IntPtr szSessionId, ushort volume);
        #endregion

        #region 语音对讲
        //Talk
        /// <summary>
        /// 开启语音对讲, 不支持多个设备同时对接 异步接口，返回值只是表示操作成功，不代表对讲开启成功 如果接口返回-1, 结果根据消息回调函数msgid判断, 若msgid=INS_VOICETALK_START, 表示成功, 若msgid=INS_VOICETALK_STOP, 表示失败
        /// </summary>
        /// <param name="szSessionId">会话Id</param>
        /// <param name="szDevSerial">设备序列号</param>
        /// <param name="iChannelNo">设备通道号</param>
        /// <returns>0表示成功，-1表示失败</returns>
        [DllImport(DllName, EntryPoint = "OpenSDK_StartVoiceTalkEx")]
        public static extern int OpenSDK_StartVoiceTalkEx(IntPtr szSessionId, string szDevSerial, int iChannelNo);

        /// <summary>
        /// 结束语音对讲
        /// </summary>
        /// <param name="szSessionId">会话Id</param>
        /// <returns>0表示成功，-1表示失败</returns>
        [DllImport(DllName, EntryPoint = "OpenSDK_StopVoiceTalk")]
        public static extern int OpenSDK_StopVoiceTalk(IntPtr szSessionId);
        #endregion

        #region 截屏
        /// <summary>
        ///  截屏，StartRealPlay成功（回调函数中收到MsgId == INS_PLAY_START）情况下使用
        /// </summary>
        /// <param name="szSessionId">会话</param>
        /// <param name="filename">文件名</param>
        /// <returns>0表示成功，-1表示失败</returns>
        [DllImport(DllName, EntryPoint = "OpenSDK_CapturePicture")]
        public static extern int OpenSDK_CapturePicture(IntPtr szSessionId, string filename);
        #endregion

        #region 数据接口-告警
        /// <summary>
        ///  获取报警列表
        /// </summary>
        /// <param name="accessToken">认证Token</param>
        /// <param name="cameraId">监控点Id</param>
        /// <param name="startTime">开始时间</param>
        /// <param name="endTime">结束时间</param>
        /// <param name="alarmType">报警类型</param>
        /// <param name="status">报警状态，0表示未读，1表示已读，2表示所有</param>
        /// <param name="pageIndex">分页起始页，从0开始</param>
        /// <param name="pageSize">分页大小</param>
        /// <param name="buf">报警信息列表</param>
        /// <param name="length">报警信息列表长度</param>
        /// <returns> 0表示成功，-1表示失败</returns>
        [DllImport(DllName, EntryPoint = "OpenSDK_Data_GetAlarmListEx")]

        public static extern int OpenSDK_Data_GetAlarmListEx(string accessToken, string cameraId, string startTime, string endTime, EZAlarmType alarmType, EZAlarmStatus status, int pageIndex, int pageSize, ref IntPtr buf, ref int length);

        /// <summary>
        /// 解密告警图片(建议加密的图片才调用，非加密图片直接下载，可以通过url里面isEncrypted=1来区分
        /// </summary>
        /// <param name="accessToken">认证Token</param>
        /// <param name="picURL">图片URL</param>
        /// <param name="deviceSerail">告警图片对应的设备序列号</param>
        /// <param name="safeKey">解密密钥，默认是设备验证码</param>
        /// <param name="picBuf">解密后图片内容（需要调用OpenSDK_Data_Free释放内存）</param>
        /// <param name="length">picBuf的长度</param>
        /// <returns> 0表示成功，-1表示失败, 失败时调用GetLastErrorCode()</returns>
        [DllImport(DllName, EntryPoint = "OpenSDK_DecryptPicture")]

        public static extern int OpenSDK_DecryptPicture(string accessToken, string picURL, string deviceSerail, string safeKey, ref IntPtr picBuf, ref int length);

        /// <summary>
        /// 更新监控点详细信息到缓存
        /// </summary>
        /// <param name="accessToken">认证Token</param>
        /// <param name="cameraId">监控点ID</param>
        /// <param name="isEncrypt">监控点设备是否加密</param>
        /// <returns>0表示成功，其他值表示失败</returns>
        [DllImport(DllName, EntryPoint = "OpenSDK_UpdateCameraInfoToLocal")]
        public static extern int OpenSDK_UpdateCameraInfoToLocal(string accessToken, string cameraId, ref bool isEncrypt);

        /// <summary>
        ///  获取设备详情监控点详细信息
        /// </summary>
        /// <param name="accessToken">认证Token</param>
        /// <param name="cameraId">监控点ID</param>
        /// <param name="buf">监控点信息，需要调用OpenSDK_FreeData接口释放</param>
        /// <param name="len">监控点信息的长度</param>
        /// <returns></returns>
        [DllImport(DllName, EntryPoint = "OpenSDK_GetCameraInfo")]
        public static extern int OpenSDK_GetCameraInfo(string accessToken, string cameraId, IntPtr buf, int len);

        /// <summary>
        /// 设置报警已读
        /// </summary>
        /// <param name="accessToken">认证Token</param>
        /// <param name="alarmId">报警ID</param>
        /// <returns>0表示成功，非0表示失败</returns>
        [DllImport(DllName, EntryPoint = "OpenSDK_Data_SetAlarmRead")]
        public static extern int OpenSDK_Data_SetAlarmRead(string accessToken, string alarmId);


        #endregion

        #region 通用工具接口(SDK Http请求接口)
        /// <summary>
        /// Http请求接口
        /// </summary>
        /// <param name="szUri">请求地址</param>
        /// <param name="szHeaderParam">头部参数</param>
        /// <param name="szBody">Body数据</param>
        /// <param name="pBuf">返回报文的内容</param>
        /// <param name="iLength">返回报文的长度</param>
        /// <returns>0表示成功，其他值表示失败</returns>
        [DllImport(DllName, EntryPoint = "OpenSDK_HttpSendWithWait")]
        public static extern int OpenSDK_HttpSendWithWait(string szUri, string szHeaderParam, string szBody, out IntPtr pBuf, out int iLength);

        #endregion

        #region  消息处理器
        /// <summary>
        /// 报警消息推送回调函数
        /// </summary>
        /// <param name="szDesc">推送描述信息</param>
        /// <param name="szContent">推送内容</param>
        /// <param name="szDetail">完整的推送信息</param>
        /// <param name="pUser">用户自定义数据</param>
        public delegate void OpenSDK_Push_MessageHandler(string szDesc, string szContent, string szDetail, IntPtr pUser);

        /// <summary>
        /// 报警消息推送回调函数
        /// </summary>
        /// <param name="cameraId">监控点Id</param>
        /// <param name="content">报警推送内容</param>
        /// <param name="alarmTime">报警推送时间</param>
        /// <param name="userData">用户自定义数据</param>
        public delegate void OpenSDK_Alarm_MessageHandler(string cameraId, string content, string alarmTime, IntPtr userData);

        /// <summary>
        /// 报警消息透传回调函数
        /// </summary>
        /// <param name="content"></param>
        /// <param name="userData"></param>
        public delegate void OpenSDK_Alarm_TransparentHandler(string content, IntPtr userData);

        /// <summary>
        /// 设置告警消息以及推送消息
        /// </summary>
        /// <param name="alarmMessageHandler">告警推送函数</param>
        /// <param name="publishMessageHandler">推送消息函数</param>
        /// <param name="userData">用户自定义数据，回调函数会原样抛出</param>
        /// <returns>0表示成功，-1表示失败</returns>
        [DllImport("OpenNetStream.dll")]
        public static extern int OpenSDK_Alarm_SetMsgCallBack(OpenSDK_Alarm_MessageHandler alarmMessageHandler, OpenSDK_Push_MessageHandler publishMessageHandler, IntPtr userData);

        /// <summary>
        /// 设置消息透传回调
        /// </summary>
        /// <param name="alarmTransparentHandler">告警透传函数</param>
        /// <param name="userData">用户自定义数据，回调函数会原样抛出</param>
        /// <returns>0表示成功，-1表示失败</returns>
        [DllImport("OpenNetStream.dll")]
        public static extern int OpenSDK_Alarm_SetTransparentCallBack(OpenSDK_Alarm_TransparentHandler alarmTransparentHandler, IntPtr userData);


        /// <summary>
        /// 设置告警通知回调
        /// </summary>
        /// <param name="notifyType">告警通知类型，比方连接异常、重连成功、重连失败</param>
        /// <param name="errorCode">错误码</param>
        /// <param name="userData">用户自定义数据，回调函数会原样抛出</param>
        public delegate void OpenSDK_Alarm_NotifyHandler(EZAlarmNotifyType notifyType, int errorCode, IntPtr userData);

        #endregion

        #region  消息推送

        /// <summary>
        ///  设置告警推送回调
        /// </summary>
        /// <param name="pHandle">告警推送函数</param>
        /// <param name="pUser">用户自定义数据，回调函数会原样抛出</param>
        /// <returns>0表示成功，-1表示失败</returns>
        [DllImport(DllName, EntryPoint = "OpenSDK_Push_SetAlarmCallBack")]
        public static extern int OpenSDK_Push_SetAlarmCallBack(OpenSDK_Push_MessageHandler pHandle, IntPtr pUser);

        /// <summary>
        /// 设置设备上下线状态推送
        /// </summary>
        /// <param name="pHandle">设备状态推送函数</param>
        /// <param name="pUser">用户自定义数据，回调函数会原样抛出</param>
        /// <returns>0表示成功，-1表示失败</returns>
        [DllImport(DllName, EntryPoint = "OpenSDK_Push_SetDeviceStatusCallBack")]
        public static extern int OpenSDK_Push_SetDeviceStatusCallBack(OpenSDK_Push_MessageHandler pHandle, IntPtr pUser);

        /// <summary>
        /// 设置设备透明通道推送
        /// </summary>
        /// <param name="pHandle">告警推送函数</param>
        /// <param name="pUser">用户自定义数据，回调函数会原样抛出</param>
        /// <returns>0表示成功，-1表示失败</returns>
        [DllImport(DllName, EntryPoint = "OpenSDK_Push_SetTransparentChannelCallBack")]
        public static extern int OpenSDK_Push_SetTransparentChannelCallBack(OpenSDK_Push_MessageHandler pHandle, IntPtr pUser);

        #endregion

        #region 错误码信息接口
        //Error Info
        /// <summary>
        /// 获取错误码接口
        /// </summary>
        /// <returns>错误码</returns>
        [DllImport(DllName, EntryPoint = "OpenSDK_GetLastErrorCode")]
        public static extern int OpenSDK_GetLastErrorCode();

        /// <summary>
        /// 获取错误码接口
        /// </summary>
        /// <returns>错误码描述字段</returns>
        [DllImport(DllName, EntryPoint = "OpenSDK_GetLastErrorDesc")]
        public static extern IntPtr OpenSDK_GetLastErrorDesc();
        #endregion

        #region  Kernel32
        [DllImport("kernel32")]
        public static extern int GetPrivateProfileString(string section, string key, string def, byte[] retVal, int size, string filePath);

        /// <summary>
        /// 内存回收
        /// </summary>
        /// <param name="process"></param>
        /// <param name="minSize"></param>
        /// <param name="maxSize"></param>
        /// <returns></returns>
        [DllImport("kernel32.dll", EntryPoint = "SetProcessWorkingSetSize")]
        public static extern int SetProcessWorkingSetSize(IntPtr process, int minSize, int maxSize);
        #endregion
    }
}
